#!/bin/bash -ex

function cleanup() {
    rm -f "/etc/cni/net.d/10-kuryr.conflist"
    rm -f "/opt/cni/bin/kuryr-cni"
}

function deploy() {
    # Copy the binary into the designated location
    cp /kuryr-cni "/opt/cni/bin/kuryr-cni"
    chmod +x /opt/cni/bin/kuryr-cni
    if [ -f /etc/cni/net.d/kuryr.conflist.template ]; then
      cp /etc/cni/net.d/kuryr.conflist.template /etc/cni/net.d/10-kuryr.conflist
    else
      cp /etc/kuryr-cni/kuryr.conflist.template /etc/cni/net.d/10-kuryr.conflist
    fi
}

cleanup
deploy

exec kuryr-daemon --config-file /etc/kuryr/kuryr.conf
